﻿using AutoMapper;
using MesProjectERP.Host.Dto.Input;
using MesProjectERP.Host.MesProjectERPDomain;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace MesProjectERP.Host.Controllers
{
    /// <summary>
    /// 客户管理
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ConsumerController : ControllerBase
    {
        private readonly MesProjectERPContext _context;
        private readonly IMapper _mapper;

        public ConsumerController(MesProjectERPContext context,IMapper mapper)
        {
            this._context = context;
            this._mapper = mapper;
        }
        /// <summary>
        /// 添加客户信息
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public int AddConsumer([FromBody]AddConsumerInput input)
        {
            var data= _mapper.Map<ConsumerModel>(input);

            _context.ConsumerModels.Add(data);
            _context.SaveChanges();

            return 1;
        }

        /// <summary>
        /// 获取客户信息
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public List<ConsumerModel> GetConsumer()
        {
            var data = _context.ConsumerModels.ToList();
            return data;
        }


    }
}
